# mods/back_to_old.py
from SuperQQBot import User
from SuperQQBot import MessageSendReceiveAPI
from SuperQQBot import Intents
from SuperQQBot.core.Error import CompatibilityWillBeUnSuppose
import warnings

TYPES = "trans_old"


def setup():
    # 动态添加 old_flags 属性到 Intents 类
    Intents.old_flags = {
        "public_messages": 'GROUP_AND_C2C_EVENT',
        'public_guild_messages':'PUBLIC_GUILD_MESSAGES'
    }

    # 修改 Intents 类的 __init__ 方法以支持旧标志
    # original_init = Intents.__init__

    def new_init(self, **kwargs: bool):
        self.value = Intents.DEFAULT_VALUE
        self.intents = {flag: False for flag in Intents.VALID_FLAGS}
        for key, value in kwargs.items():
            if key in Intents.old_flags:
                (warnings
                 .warn(CompatibilityWillBeUnSuppose(key, Intents.old_flags[key])))
                self.intents[Intents.old_flags[key]] = value
                continue
            if key not in Intents.VALID_FLAGS:
                raise TypeError(f"{key!r} 是无效的标志名称。")
            self.intents[key] = value
        self._update_bitwise_value()

    Intents.__init__ = new_init

    # 动态添加 name 属性到 User 类
    def name(self):
        (warnings
         .warn(CompatibilityWillBeUnSuppose('self.robot.name', 'self.robot.username')))
        return self.username

    User.name = property(name)
    async def post_message(self, **kwargs):
        (warnings
         .warn(CompatibilityWillBeUnSuppose('BotSendReceiveAPI.post_message', 'BotSendReceiveAPI.post_channel_message')))
        return await self.post_channel_messages(**kwargs)
    MessageSendReceiveAPI.post_message = post_message
# 执行 setup 函数来应用更改
setup()